package com.oro.domain;

import static javax.persistence.CascadeType.ALL;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;

/**
 * Entity implementation class for Entity: TranslatorReferral
 * 
 */
@Entity
public class TranslatorReferral extends Proposal implements Serializable {

	private static final long serialVersionUID = 1L;

	@ManyToOne(cascade = ALL)
	@JoinTable(name = "translatorreferral_studente")
	private Studente student;

	@ManyToOne(cascade = ALL)
	@JoinTable(name = "translatorreferral_traduttore")
	private Traduttore translator;

	public TranslatorReferral() {
		super();
		setCanOverrideTotalCost(true);
		setCanPercentageTotalCost(true);
		setCanSubtractTotalCost(true);
		setCanOverrideWeeklyCost(false);
		setCanPercentageWeeklyCost(false);
		setCanSubtractWeeklyCost(false);
	}

	@Override
	public boolean equals(Object o) {
		if (o == null)
			return false;
		if (!(o instanceof MigrationAgent))
			return false;
		TranslatorReferral ma = (TranslatorReferral) o;
		if (this == ma)
			return true;
		if (getId() != null && getId() != 0L)
			return getId().equals(ma.getId());
		else {
			return getStudent().equals(ma.getStudent())
					&& getTranslator().equals(ma.getTranslator());
		}
	}

	@Override
	public boolean getCanOverrideTotalCost() {
		return true;
	}

	@Override
	public boolean getCanOverrideWeeklyCost() {
		return false;
	}

	@Override
	public boolean getCanPercentageTotalCost() {
		return true;
	}

	@Override
	public boolean getCanPercentageWeeklyCost() {
		return false;
	}

	@Override
	public boolean getCanSubtractTotalCost() {
		return true;
	}

	@Override
	public boolean getCanSubtractWeeklyCost() {
		return false;
	}

	@Override
	public float getDiscountedCost() {
		float result = getTotalCost();
		if (getCanPercentageTotalCost())
			result = result * (100 - getDiscount().getPercentageTotalCost())
					/ 100;
		if (getCanSubtractTotalCost())
			result = result - getDiscount().getSubtractTotalCost();
		if (getCanOverrideTotalCost())
			if (!(getDiscount().getOverrideTotalCost() < 0))
				result = getDiscount().getOverrideTotalCost();
		return result;
	}

	public Studente getStudent() {
		return student;
	}

	public Traduttore getTranslator() {
		return translator;
	}

	@Override
	public void setCanOverrideTotalCost(boolean canOverrideTotalCost) {

	}

	@Override
	public void setCanOverrideWeeklyCost(boolean canOverrideWeeklyCost) {

	}

	@Override
	public void setCanPercentageTotalCost(boolean canPercentageTotalCost) {

	}

	@Override
	public void setCanPercentageWeeklyCost(boolean canPercentageWeeklyCost) {

	}

	@Override
	public void setCanSubtractTotalCost(boolean canOrNot) {
	}

	@Override
	public void setCanSubtractWeeklyCost(boolean canSubtractWeeklyCost) {
	}

	public void setStudent(Studente student) {
		this.student = student;
	}

	public void setTranslator(Traduttore translator) {
		this.translator = translator;
	}

}
